#include<iostream>
using namespace std;

int main()
{
	int r, y, g;
	cin >> r >> y >> g;
	int n;
	cin >> n; 
	int k, t;
	int sum = 0;
	int n_time = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> k >> t;
		switch (k)
		{
			case 0: sum += t; break;
			case 1: sum += t; break;
			case 2: sum += t+r; break;
		}
	}
	cout << sum;
	return 0;
} 
